<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 优惠券管理
 */
namespace app\ais\model;
use think\Model;

class AisCoupon extends Model{

    protected $pk = 'id';

    public function getTypesnameAttr($value,$data){
        $status = [0 =>'代金券',1 =>'折扣券',2 =>'兑换券',3 =>'储值券'];
        return $status[$data['types']];
    }

    public function getDegreeAttr($value,$data){
        $status = [0 =>'￥'.$data['price'],1 => $data['discount'].' 折',2 => $data['price'].' 次',3 => '￥'.$data['amount']];
        return $status[$data['types']];
    }

    /**
     * 好店信息
     * @return void
     */
    public function store(){
        return $this->hasOne('AisStore','id','store_id');
    }
    
    /**
     * 用户已领油
     * @return void
     */
    public function couponuser(){
        return $this->hasOne('AisCouponUser','coupon_id','id');
    }

    //搜索好店名称
    public function searchNameAttr($query,$value){
        if(!empty($value)){
            $query->where('name','like', '%'.$value .'%');
        }
    }
}